#!/usr/bin/env python

import sys, os

from python import cavan_tc3587xx
from python.cavan_stdio import pr_red_info, pr_green_info

if __name__ == "__main__":
	if len(sys.argv) < 2:
		print "%s <SOURCE> [DEST]" % sys.argv[0]
		sys.exit(-1)

	src_file = sys.argv[1]
	if len(sys.argv) > 2:
		dest_file = sys.argv[2]
	else:
		dest_file = src_file + ".c"

	print "%s => %s" % (src_file, dest_file)

	convert = cavan_tc3587xx.TC3587XX_Converter()
	if not convert.doConvertXml(src_file) and not convert.doConvertText(src_file):
		sys.exit(-1)

	if not convert.save(dest_file):
		sys.exit(-1)

	pr_green_info("OK")
